package com.webtest.jsptest;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author lzy
 * @version v1.0
 * Create DateTime: 2018/7/24 15:46
 */
public class RedirectServlet extends HttpServlet {
    private static final long serialVersionUID = -7730311480214971612L;

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("RedirectServlet's doGet");
        req.setAttribute("name", "xyz");
        System.out.println("Redirect servlet: " + req.getAttribute("name"));

        // 执行请求的重定向, 直接调用resp.sendRedirect(path)方法
        // path为重定向的地址
        String path = "testServlet";
        resp.sendRedirect(path);
    }
}
